package com.sharkpro.utils;

import lombok.Data;

/**
 * @author jianxin.wei
 * @description 返回工具类
 * @date 2024/12/16 10:42
 */
@Data
public class ResultUtil {
    //0:失败 1：成功
    private int code = 0;
    private String msg;
    private Object data;
    private boolean success = false;



    public  ResultUtil fail(String resultMessage) {
        this.msg = resultMessage;
        this.code = 0;
        this.data = "";
        this.success = false;
        return this;
    }

    public  ResultUtil fail(int code , String resultMessage) {
        this.msg = resultMessage;
        this.code = code;
        this.data = "";
        this.success = false;
        return this;
    }

    public  ResultUtil success(){
        this.data = "";
        this.code = 1;
        this.msg = "请求成功";
        this.success = true;
        return this;
    }

    public  ResultUtil success(Object data){
        this.data = data;
        this.code = 1;
        this.msg = "请求成功";
        this.success = true;
        return this;
    }



    @Override
    public  String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", success=" + success +
                '}';
    }
}
